package zhieasy.cn.common.utils;

import org.springframework.stereotype.Service;
import zhieasy.cn.common.strategy.FileUpload;
import zhieasy.cn.common.vo.ResultVO;

import java.util.UUID;

/**
 * @author Dahang
 * 对象存储的工具类，目前可以解决前端从后端获取不同模块所对应的上传url地址以及token
 */
@Service
public class StorageUtil {
    private final FileUpload fileUpload;

    public StorageUtil(FileUpload fileUpload) {
        this.fileUpload = fileUpload;
    }

    //二手书城前端获取token然后上传图片
    //返回token+上传路径
    public ResultVO getTokenAndUrlInBookMarket(){
        String articleId = UUID.randomUUID().toString();
        return fileUpload.getTokenAndUrlInBookMarket("book_market");
    }
    //失物招领前端获取token然后上传图片
    public ResultVO getTokenAndUrlInFound(String articleId){
        return fileUpload.getTokenAndUrlInBookMarket("found");
    }
    //论坛前端获取token然后上传图片
    public ResultVO getTokenAndUrlInChat(){
        return fileUpload.getTokenAndUrlInBookMarket("chat" );
    }
    //课程表前端获取token然后上传图片
    public ResultVO getTokenAndUrlInCourse(){
        return fileUpload.getTokenAndUrlInBookMarket("course" );
    }
    //开学助手前端获取token然后上传图片
    public ResultVO getTokenAndUrlInInitiation(){
        return fileUpload.getTokenAndUrlInBookMarket("initiation" );
    }
}
